package com.zzyl.controller;


import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags="护理等级")
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult listAll(){
        List<NursingLevelVo> list = nursingLevelService.listAll();
        return success(list);
    }


    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult insert(@ApiParam(value = "新增护理等级参数") @RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.insert(nursingLevelDto);
        return success();
    }


    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(@ApiParam(value = "护理等级名称") String name,
                                                                   @ApiParam(value = "页码")Integer pageNum,
                                                                   @ApiParam(value = "每页大小")Integer pageSize,
                                                                   @ApiParam(value = "护理等级状态")Integer status){
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.listByPage(name,pageNum,pageSize,status);
        return success(pageResponse);
    }



    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult getById(@ApiParam(value = "id")@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@ApiParam(value = "修改参数对象")@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@ApiParam(value = "id")@PathVariable Long id){
        nursingLevelService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult statusChange(@ApiParam(value = "id")@PathVariable Long id,
                                       @ApiParam(value = "状态")@PathVariable Integer status){
        nursingLevelService.statusChange(id,status);
        return success();
    }



}
